
class Edge:
    def __init__(self, begin, end, chr):
        self.begin = begin # 开始状态
        self.end = end # 结束状态
        self.chr = chr # 边上字符

    def print(self):
        print(f"{self.begin}-{self.chr}->{self.end}", end=" ")


class NFAGraph:
    def __init__(self):
        self.begin = -1
        self.end = 0
        self.edges = [] # 所有的边集

    def add_edge(self, edge):
        self.edges.append(edge)


def insert_concat(s):
    res = []
    for i in range(len(s)):
        res.append(s[i])
        if s[i] in "(|":
            continue
        if i == len(s) - 1:
            continue
        if s[i + 1] not in "*)|":
            res.append('+')
        # if s[i + 1] == "(":
        #     res.append('+')
    # print(''.join(res))
    return ''.join(res)


def to_rpn(s):
    stack = []
    res = []
    priority = {'*': 3, '|': 2, '+': 1, '(': 0, ')': 0}

    for char in s:
        if char == '(':
            stack.append(char)
        elif char == ')':
            while stack[-1] != '(':
                res.append(stack.pop())
            stack.pop()
        elif char in priority:
            while stack and priority[stack[-1]] >= priority[char]:
                res.append(stack.pop())
            stack.append(char)
        else:
            res.append(char)

    while stack:
        res.append(stack.pop())
    # print(''.join(res))
    return ''.join(res)


def regex_to_nfa(reg):
    nfa = NFAGraph()
    tmp = []

    for i in range(len(reg)):
        if i == 0 or (reg[i].isalnum() and reg[i - 1].isalnum()):
            tmp.append(Edge(nfa.begin, nfa.end, reg[i]))
        elif reg[i].isalnum() and (reg[i - 1] in "|*+"):
            for edge in tmp:
                nfa.add_edge(edge)
            tmp.clear()
            tmp.append(Edge(nfa.begin, nfa.end, reg[i]))
        elif reg[i] == '+':
            nfa.begin += 1
            nfa.end += 1
            if reg[i - 1].isalnum():
                tmp[-1].begin = nfa.begin
                tmp[-1].end = nfa.end
        elif reg[i] == '|':
            nfa.edges.append(Edge(nfa.begin, nfa.end, '~'))
            nfa.begin += 1
            nfa.end += 1
            nfa.edges.append(Edge(nfa.begin, nfa.end, '~'))
            tmp[0].begin = nfa.begin
            tmp[0].end = nfa.end
            tmp[-1].begin = nfa.begin
            tmp[-1].end = nfa.end
        elif reg[i] == '*':
            if reg[i - 1] == '+':
                begin = tmp[0].begin
                end = tmp[-1].end
                nfa.add_edge(Edge(begin, end, '~'))
                nfa.add_edge(Edge(end, begin, '~'))
            elif reg[i - 1] == '|':
                tmp[0].end = tmp[0].begin
                tmp[-1].end = tmp[-1].begin
            elif reg[i - 1].isalnum():
                nfa.begin += 1
                nfa.end += 1
                tmp[-1].begin = nfa.begin
                tmp[-1].end = nfa.end
                begin = tmp[-1].begin
                end = tmp[-1].end
                nfa.add_edge(Edge(begin, end, '~'))
                nfa.add_edge(Edge(begin+1, end+1, '~'))
                tmp[-1].begin = tmp[-1].end

    for edge in tmp:
        nfa.edges.append(edge)

    return nfa


def print_nfa(nfa):
    for e in nfa.edges:
        if e.begin == -1:
            print(f"X X-{e.chr}->{e.end}")
            print("Y")
    for i in range(nfa.end-1):
        print(i, end=' ')
        for e in nfa.edges:
            if e.begin == i:
                e.print()
        print()
    flag = False
    for e in nfa.edges:
        if e.begin == nfa.end-1:
            if e.end == nfa.end:
                if not flag:
                    print(e.begin, end=' ')
                    flag = True
                print(f"{e.begin}-{e.chr}->Y", end=' ')
            else:
                e.print()

if __name__ == "__main__":
    # 从标准输入读取一行
    str = input().strip()  # 使用input()代替getline(cin, str)
    # print(f"str:{str}")
    str = insert_concat(str)
    # print(f"concat_str:{str}")
    rpn = to_rpn(str)
    # print(f"rpn_str:{rpn}")
    nfa = regex_to_nfa(rpn)
    print_nfa(nfa)